package net.swl.linkedvillage;

import java.util.List;

import net.swl.linkedvillage.util.GestorParse;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnGenericMotionListener;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.TextView;

import com.parse.FindCallback;
import com.parse.Parse;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.R.color;
public class IndexActivity extends Activity {


	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_index);
		Parse.initialize(this, "VfKri7peCV168zVhdWZBZ8zwZmjZBqWs1GL7Hcoi","0iuOEQKfh6dVM6Y8UYwjAXphYtPchnyEO12jxCyy");
		GestorParse gestorParse = new GestorParse(this);
		getActionBar().setIcon(R.drawable.logo_linkedvillage);
		setTitle("");
		
		gestorParse.getPedidosEmCursoUser(new FindCallback<ParseObject>() {
			@Override
			public void done(List<ParseObject> arg0, ParseException arg1) {
				setPedidosEmCurso(arg0);
			}
		});
		
		gestorParse.getPedidosEmPendentesUser(new FindCallback<ParseObject>() {
			@Override
			public void done(List<ParseObject> arg0, ParseException arg1) {
				setPedidosPendentes(arg0);
			}
		});
		
		gestorParse.getServicosEmCursoUser(new FindCallback<ParseObject>() {
			@Override
			public void done(List<ParseObject> arg0, ParseException arg1) {
				setServicosEmCurso(arg0);
			}
		});
		
		gestorParse.getServicosEmCursoUser(new FindCallback<ParseObject>() {
			@Override
			public void done(List<ParseObject> arg0, ParseException arg1) {
				setServicosPendentes(arg0);
			}
		});
		
		OnTouchListener listener = new OnTouchListener() {
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				Log.d("touch", Integer.toString(event.getActionMasked()));
				if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
					v.setBackgroundColor(getResources().getColor(R.color.verdeTexto));
				} else if (event.getActionMasked() == MotionEvent.ACTION_UP)  {
					v.setBackgroundColor(getResources().getColor(R.color.verdeCinza));
				}
				return false;//
			}
		};
		
		findViewById(R.id.osMeusPedidos).setOnTouchListener(listener);
		findViewById(R.id.osMeusServicos).setOnTouchListener(listener);
		findViewById(R.id.pesquisa).setOnTouchListener(listener);
		findViewById(R.id.editarServicos).setOnTouchListener(listener);
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.index, menu);
		return true;
	}
	
	public void setPedidosEmCurso(List<ParseObject> objs) {
		/**
		TextView v = (TextView) findViewById(R.id.textViewPedidosEmCurso);
		v.setText(String.format("%d em curso", objs.size()));
		*/
	}
	
	public void setPedidosPendentes(List<ParseObject> objs) {
		/*
		//TextView v = (TextView) findViewById(R.id.textViewPedidosP);
		v.setText(String.format("%d pendentes", objs.size()));
		*/
	}
	
	public void setServicosEmCurso(List<ParseObject> objs) {
		/*
		TextView v = (TextView) findViewById(R.id.textViewServicosEmCurso);
		v.setText(String.format("%d trabalhos em curso", objs.size()));
		*/
	}
	
	public void setServicosPendentes(List<ParseObject> objs) {
		/*
		TextView v = (TextView) findViewById(R.id.textViewServicosPendentes);
		v.setText(String.format("%d novos trabalhos", objs.size()));
		*/
	}


	public void onMeusPedidosClick(View v) {
		v.setBackgroundColor(getResources().getColor(R.color.verdeTexto));
		Intent i = new Intent(this, MeusPedidosActivity.class);
		v.setBackgroundColor(getResources().getColor(R.color.verdeEscuro));
		startActivity(i);
	}
	
	public void onPesquisaClick(View v) {
		v.setBackgroundColor(getResources().getColor(R.color.verdeTexto));
		Intent i = new Intent(this, ResultadosProcura.class);
		v.setBackgroundColor(getResources().getColor(R.color.verdeEscuro));
		startActivity(i);
	}
	
	public void onMeusServicosClick(View v) {
		v.setBackgroundColor(getResources().getColor(R.color.verdeTexto));
		Intent i = new Intent(this, MeusPedidosActivity.class);
		startActivity(i);
		v.setBackgroundColor(getResources().getColor(R.color.verdeEscuro));
	}
	
	public void onEditarMeusServicosClick(View v) {
		v.setBackgroundColor(getResources().getColor(R.color.verdeTexto));
		Intent i = new Intent(this, EditarServicos.class);
		startActivity(i);
		v.setBackgroundColor(getResources().getColor(R.color.verdeEscuro));
	}

}
